package com.blockchainenergy.common;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * 时间轮询控制类，每个小时调用DealMatcher来执行撮合
 */
@Component
public class TimePollingController {

    public static TimePollingController controller;

    @PostConstruct
    public void init() {
        controller = this;
    }

    // 每小时执行
    @Scheduled(cron = "0 0 * * * ?")
    public void timePolling() throws Exception {
//        LocalDate date = LocalDate.now();
//        int hour = LocalTime.now().getHour();
//
//        System.out.println("开始撮合：" + LocalDateTime.now());
//        controller.dealMatchingService.executeMatching(date, hour);
//        System.out.println("结束撮合：" + LocalDateTime.now());
//
//        System.out.println("====== 记录电表数据到数据库日志 ======");
//        controller.mqttService.insertElectricityMeterLog(hour);
//        System.out.println("====== 记录完成 ======");
    }

    // 每天0点0分
    @Scheduled(cron = "0 0 0 * * ?")
    public void timePolling1() throws Exception {
        CarbonTools.singlecalculation();
    }
}
